var search_view = {
init: 
    function () {
        
    },

open:
    function (query_text) {
        var keywords = query_text.split(' ');
        ubi.tabs.select('#search-view');        
        search_do(query_text,
            function (state, data) {
                var results = data;
                var results_array = new Array();
                for (var i = 0; i < results.length; i += 1) {   
                    results_array.push(
                        form_result(results[i].note_id,
                            results[i].title,
                            results[i].block_id,
                            results[i].content));
                }
                
                var html_str = results_array.join('');
                for (var i in keywords) {
                    keyword =$.trim(keywords[i])
                    if (keyword != '')
                        html_str = html_str.replace(
                            new RegExp(keyword, 'gi'), 
                            '<span class="hlight">'+keyword+'</span>');
                }
                $('#search-view-content').html(html_str)
                search_view.bind_result_item_title_click();                
            },
            function (state, data) {
                notify('Load search result fail.')
            }
        );
    },

bind_result_item_title_click:
    function () {
        $('.result-item-title').unbind('click');
        $('.result-item-title').click(function () {
            var note_id = $($(this).parents('.result-item')[0]).attr('id').toString().split('_')[0];
            var block_id = $($(this).parents('.result-item')[0]).attr('id').toString().split('_')[1];
            //open a note
            ubi.notebook_view.open_note(note_id, block_id);
            return true;
        });
    }

}
